<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="案号" prop="ah">
        <el-input
          v-model="queryParams.ah"
          placeholder="请输入案号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件类型" prop="ajlx">
        <el-select v-model="queryParams.ajlx" placeholder="请选择案件类型" clearable>
          <el-option
            v-for="dict in dict.type.fs_gw_ajlx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="案件名称" prop="ajmc">
        <el-input
          v-model="queryParams.ajmc"
          placeholder="请输入案件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="所属人id" prop="ownerId">-->
<!--        <el-input-->
<!--          v-model="queryParams.ownerId"-->
<!--          placeholder="请输入所属人id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fs:case:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="caseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="案号" align="center" prop="ah" />
      <el-table-column label="案件名称" align="center" prop="ajmc" />
      <el-table-column label="经办法院" align="center" prop="fymc" />
      <el-table-column label="立案案由" align="center" prop="sqlaayMc" />
      <el-table-column label="案件类型" align="center" prop="sqlx">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fs_gw_ajlx" :value="scope.row.ajlx"/>
        </template>
      </el-table-column>
      <el-table-column label="立案日期" align="center" prop="gxsj" />
      <el-table-column label="所属人" align="center" prop="owner" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleJa(scope.row)"
            v-hasPermi="['fs:case:edit']"
          >手动结案</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改案件信息对话框 -->
    <el-dialog class="detail" :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <h3>案件信息</h3>
        <el-row>
          <el-col :span="24">
            <el-form-item label="经办法院：">{{ fullView.jbfy }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="案件名称：">{{ form.ajmc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案号：">{{ form.ah }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件类型：">{{ form.ajlxMc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="立案案由：">{{ fullView.laay }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="立案日期：">{{ fullView.larq }}</el-form-item>
          </el-col>
        </el-row>
        <h3>庭审信息</h3>
        <el-row>
          <el-col :span="12">
            <el-form-item label="承办审判庭：">{{ fullView.cbts }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="承办人：">{{ fullView.cbr }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法庭名称：">{{ fullView.ftmc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公开审理：">{{ fullView.gksl }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始时间：">{{ fullView.kssj }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间：">{{ fullView.jssj }}</el-form-item>
          </el-col>
        </el-row>
        <h3>原告</h3>
        <el-row>
          <el-col :span="24">
            <el-form-item label="当事人类型：">
              <dict-tag :options="dict.type.fs_gw_dsrlx" :value="ygDsr.dsrlx"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="ygDsr.dsrlx==2">
          <el-col :span="12">
            <el-form-item label="单位名称：">{{ ygDsr.dwmc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位性质：">
              <dict-tag :options="dict.type.fs_gw_dwxz" :value="ygDsr.dwxz"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证照类型：">
              <dict-tag :options="dict.type.fs_gw_zzlx" :value="ygDsr.zzlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证照号码：">{{ ygDsr.zzh }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人姓名：">{{ ygDsr.fddbr }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人职务：">{{ ygDsr.fddbrzw }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人证件类型：">
              <dict-tag :options="dict.type.fs_gw_zjlx" :value="ygDsr.zjlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人证件号码：">{{ ygDsr.zjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人手机号码：">{{ ygDsr.sjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人固定电话：">{{ ygDsr.gddh }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="主要办事地址：">{{ ygDsr.zybsjgszd }}</el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="ygDsr.dsrlx==1">
          <el-col :span="12">
            <el-form-item label="姓名：">{{ ygDsr.xm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件类型：">
              <dict-tag :options="dict.type.fs_gw_zjlx" :value="ygDsr.zjlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码：">{{ ygDsr.zjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别：">
              <dict-tag :options="dict.type.sys_user_sex" :value="ygDsr.xb"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄：">{{ ygDsr.nl }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期：">{{ ygDsr.csrq }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族：">
              <dict-tag :options="dict.type.fs_gw_mz" :value="ygDsr.mz"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职业：">
              <dict-tag :options="dict.type.fs_gw_zy" :value="ygDsr.zy"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作单位：">{{ ygDsr.gzdw }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码：">{{ ygDsr.sjhm }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="地址：">{{ ygDsr.dz }}</el-form-item>
          </el-col>
        </el-row>

        <h3>被告</h3>
        <el-row>
          <el-col :span="24">
            <el-form-item label="当事人类型：">
              <dict-tag :options="dict.type.fs_gw_dsrlx" :value="bgDsr.dsrlx"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="bgDsr.dsrlx==2">
          <el-col :span="12">
            <el-form-item label="单位名称：">{{ bgDsr.dwmc }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位性质：">
              <dict-tag :options="dict.type.fs_gw_dwxz" :value="bgDsr.dwxz"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证照类型：">
              <dict-tag :options="dict.type.fs_gw_zzlx" :value="bgDsr.zzlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证照号码：">{{ bgDsr.zzh }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人姓名：">{{ bgDsr.fddbr }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人职务：">{{ bgDsr.fddbrzw }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人证件类型：">
              <dict-tag :options="dict.type.fs_gw_zjlx" :value="bgDsr.zjlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人证件号码：">{{ bgDsr.zjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人手机号码：">{{ bgDsr.sjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人固定电话：">{{ bgDsr.gddh }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="主要办事机构所在地：">{{ bgDsr.zybsjgszd }}</el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="bgDsr.dsrlx==1">
          <el-col :span="12">
            <el-form-item label="姓名：">{{ bgDsr.xm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件类型：">
              <dict-tag :options="dict.type.fs_gw_zjlx" :value="bgDsr.zjlx"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码：">{{ bgDsr.zjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别：">
              <dict-tag :options="dict.type.sys_user_sex" :value="bgDsr.xb"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年龄：">{{ bgDsr.nl }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生日期：">{{ bgDsr.csrq }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族：">
              <dict-tag :options="dict.type.fs_gw_mz" :value="bgDsr.mz"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职业：">
              <dict-tag :options="dict.type.fs_gw_zy" :value="bgDsr.zy"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作单位：">{{ bgDsr.gzdw }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码：">{{ bgDsr.sjhm }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址：">{{ bgDsr.dz }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="jatitle" :visible.sync="jaopen" width="600px" append-to-body>
      <el-form ref="form" :model="jaform" label-width="160px">
        <el-form-item label="结案方式" prop="sdzt">
          <el-select v-model="jaform.sdzt" placeholder="请选择结案类型">
            <el-option
              v-for="dict in dict.type.fs_ja_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否生成还款账单" prop="status">
          <el-radio-group v-model="jaform.ifBill">
            <el-radio
              v-for="dict in dict.type.fs_yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="jaform.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCase, getCase, delCase, addCase, updateCase, ja } from "@/api/fs/case";

export default {
  name: "Case",
  dicts: ['sys_user_sex','fs_gw_dsrlx','fs_gw_dzlx', 'fs_gw_layyzt', 'fs_gw_ajlx', 'fs_ja_type',
    'fs_gw_mz', 'fs_gw_zy', 'fs_gw_sqlx', 'fs_gw_dwxz', 'fs_gw_zzlx', 'fs_gw_zjlx', 'fs_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 案件信息表格数据
      caseList: [],
      shList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      jatitle: "",
      jaopen: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ah: null,
        yg: null,
        bg: null,
        ajlx: null,
        ajmc: null,
        fyid: null,
        sqbdje: null,
        sqlaay: null,
        zt: null,
        cjsj: null,
        gxsj: null,
        ownerId: null,
        ajzt:1,
      },
      // 表单参数
      form: {},
      jaform: {},
      ygDsr: {},
      bgDsr: {},
      fullView: {},
      // 表单校验
      rules: {
        ajlx: [
          { required: true, message: "案件类型不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.reset();
  },
  methods: {
    /** 查询案件信息列表 */
    getList() {
      this.loading = true;
      listCase(this.queryParams).then(response => {
        this.caseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.jaopen = false;
      this.reset();
    },
    shcancel() {
      this.shOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        localId: null,
        bh: null,
        ah: null,
        bhLs: null,
        yg: null,
        ygbh: null,
        bg: null,
        bgbh: null,
        ajlx: null,
        ajlxMc: null,
        ajmc: null,
        bzqx: null,
        fyid: null,
        fymc: null,
        dzlx: null,
        sqbdje: null,
        sqlaay: null,
        sqlx: null,
        sqlxMc: null,
        zt: null,
        cjsj: null,
        gxsj: null,
        ownerId: null,
        owner: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.ygDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.bgDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.fullView = {
        id: null,
        bh: null,
        ah: null,
        ajmc: null,
        larq: null,
        laay: null,
        sycx: null,
        sasj: null,
        cbts: null,
        cbr: null,
        ftmc: null,
        kssj: null,
        jssj: null,
        gksl: null,
        ftyt: null,
        jbfy: null,
        zdslfy: null,
        jafs: null,
        jaay: null,
        jarq: null,
        dlrid: null,
        dlr: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.jaform = {
        id: null,
        sdzt: null,
        ifBill: null,
        remark: null
      }
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.ajzt = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getCase(id).then(response => {
        this.form = response.data;
        this.ygDsr = response.data.ygDsr;
        this.bgDsr = response.data.bgDsr;
        this.fullView = response.data.fullView;
        this.open = true;
        this.title = "案件信息";
      });
    },
    /** 结案按钮操作 */
    handleJa(row) {
      console.log(row);
      const id = row.id || this.ids
      this.jaform.id = id;
      this.jaopen = true;
      this.jatitle = "手动结案";
    },
    /** 提交按钮 */
    submitForm() {
      ja(this.jaform).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.jaopen = false;
        this.getList();
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fs/case/export', {
        ...this.queryParams
      }, `case_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped lang="scss">
  .detail .el-form-item{
    margin-bottom: 0px;
  }
  h3{
    font-family: inherit;
    font-weight: 500;
    line-height: 1.1;
    color: inherit;
    background: #e6ebf5;
    padding: 10px;
    margin: 10px 0;
  }
</style>
